<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>企业认证</title>
    <link rel="stylesheet" href="../../css/main.css" media="all">
    <link rel="stylesheet" href="../../css/admin.css" media="all">
    <link rel="stylesheet" href="../../css/enterpriseauth.css" media="all">
</head>
<body style="background-color: #ff0000!important;">
<div id="LAY_app">
    <div class="layui-card"><!--style="height: 100%;width: 100%;position: absolute"-->
        <div style="height: 30px"></div>
        <form class="layui-form" action="" lay-filter="component-form-group">
            <div class="layui-row" style="padding-right: 50px">
                <div class="layui-col-md1">&nbsp;</div>
                <!--左边栏-->
                <div class="layui-col-xs6 layui-col-sm6 layui-col-md5">
                    <div class="layui-form-item">
                        <label class="layui-form-label">注册资本</label>
                        <div class="layui-col-md7">
                            <input type="text" name="registercapital" placeholder="注册资本" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="">社会信用代码</label>
                        <div class="layui-col-md7">
                            <input type="text" name="usccode" placeholder="社会信用代码" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="">企业规模</label>
                        <div class="layui-col-md7">
                            <select name="scale">
                                <option value="" selected="selected">请选择企业规模</option>
                                <option value="0-20人">0-20人</option>
                                <option value="20-99人">20-99人</option>
                                <option value="100-499人">100-499人</option>
                                <option value="500-999人">500-999人</option>
                                <option value="1000-9999人">1000-9999人</option>
                                <option value="10000人以上">10000人以上</option>
                                <option value="不限">不限</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="">企业类型</label>
                        <div class="layui-col-md7">
                            <select name="enterprisetype">
                                <option value="">请选择企业类型</option>
                                <option value="有限责任公司(自然人投资或控股)">有限责任公司(自然人投资或控股)</option>
                                <option value="国企">国企</option>
                            </select>
                        </div>
                    </div>
                </div>
                <!--右边栏-->
                <div class="layui-col-xs6 layui-col-sm6 layui-col-md5 layui-col-md-offset1">
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="">成立日期</label>
                        <div class="layui-col-md7">
                            <input type="text" name="originatetime" id="LAY-component-form-group-date" lay-verify="date"
                                   placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="">工商注册号</label>
                        <div class="layui-col-md7">
                            <input type="text" name="brncode" placeholder="工商注册号" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="">组织机构代码</label>
                        <div class="layui-col-md7">
                            <input type="text" name="organizationcode" placeholder="组织机构代码" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="">行业类型</label>
                        <div class="layui-col-md7">
                            <select name="industry" id="jobType">
                                <option value="">请选择行业类型</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item" style="width:95%;height: 200px;margin-left: 8.2%">
                    <div class="layui-inline" style="width: 100%;height: 100%">
                        <label class="layui-form-label">经营范围</label>
                        <textarea name="scopeofbusiness" placeholder="请输入经营范围" class="layui-textarea "
                                  style="width: 78.5%;height: 150px;resize: none;font-size: 16px"></textarea>
                    </div>
                </div>

                <div class="layui-form-item" style="width:95%;height: 200px;margin-left: 8.2%">
                    <div class="layui-inline" style="width: 100%;height: 100%">
                        <label class="layui-form-label">公司简介</label>
                        <textarea name="companyprofile" placeholder="请输入公司简介" class="layui-textarea "
                                  style="width: 78.5%;height: 150px;resize: none;font-size: 16px"></textarea>
                    </div>
                </div>

                <div class="layui-form-item" style="text-align: center">
                    <button class="layui-btn" style="width: 120px;height:50px;background-color: #ff6000" lay-submit
                            lay-filter="formauthinfo">更改信息
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
</div>
</body>
<script src="../../libs/layui/layui.js"></script>
<script src="../../js/model.js"></script>
<script>
    layui.use(['layer', 'form', 'laydate', 'okLayer', 'jquery'], function () {
            let layer = layui.layer;
            let form = layui.form;
            let laydate = layui.laydate;
            let okLayer = layui.okLayer;
            let $ = layui.jquery;

            // 获取contentText
            const ctx = function () {
                let pathName = document.location.pathname;
                let index = pathName.substr(1).indexOf("/");
                let result = pathName.substr(0, index + 1);
                return result;
            }();

            // 获取enterprise
            var enterprise = JSON.parse(window.sessionStorage.getItem("enterprise"));
            endetection(enterprise);

            /**
             * 企业权限检测
             * @param en 企业对象 obj
             */
            function endetection(en) {
                if (en.certificationstatus == "1") {
                    okLayer.grayLockMsg("您已经提交认证信息，无需重复提交", function () {
                        parent.location.reload();
                    });
                } else if (en.certificationstatus == "2" || en.certificationstatus == "3") {
                    //加载企业类型
                    loadentype();
                    //渲染数据
                    authinforender();
                }
                //加载企业类型
                loadentype();
            }


            // 重新请求企业数据
            function freshstatus() {
                $.ajax({
                    url: ctx + "/ygssecs/getenterByid",
                    type: "GET",
                    data: {priseid: enterprise.enterpriseid},
                    dataType: "JSON"
                }).done(function (response) {
                    if (response.code == 200) {
                        window.sessionStorage.setItem("enterprise", JSON.stringify(response.data));
                    }
                })
            }

            //加载上次提交的数据
            function authinforender() {
                var loadIndex;
                $.ajax({
                    url: ctx + "/ygssecs/getenterinfo",
                    type: 'GET',
                    data: {enterpriseid: enterprise.enterpriseid},
                    dataType: 'JSON',
                    beforeSend: function () {
                        loadIndex = layer.load(1, {shade: 0.3});
                    }
                }).done(function (resdata) {
                    var edata = resdata.data;
                    form.val("component-form-group", edata);
                    layer.close(loadIndex);
                }).fail(function (error) {
                    console.log(error);
                })
            }

            //加载企业类型
            function loadentype() {

                $.ajax({
                    url: ctx + "/ygssecs/getjobType",
                    type: 'GET',
                    dataType: 'JSON'
                    // headers: {"token": sessionStorage.getItem("token")},
                }).done(function (datas) {
                    var list = datas['data'];
                    var option;
                    for (var i = 0; i < list.length; i++) {
                        option += "<option value='" + list[i]['typename'] + "'>" + list[i]['typename'] + "</option>";//拼接option中的内容
                        //将option的拼接内容加入select中，注意选择器是select的ID
                    }
                    $("#jobType").append(option);
                    form.render('select');//重点：重新渲染select
                }).fail(function () {
                    console.log("error");
                });
            }

            //提交认证
            form.on('submit(formauthinfo)', function (data) {
                var authinfo = new AuthInfomation(null, data.field.registercapital, data.field.originatetime, data.field.enterprisetype, data.field.usccode, data.field.brncode, data.field.organizationcode, data.field.industry, data.field.scale, data.field.scopeofbusiness, data.field.companyprofile, enterprise);
                var loadstatus;
                $.ajax({
                    url: ctx + "/ygssecs/updataauthinfo",
                    type: "POST",
                    data: {authinfo: JSON.stringify(authinfo)},
                    dataType: "JSON",
                    beforeSend: function () {
                        loadstatus = layer.load(1, {shade: 0.3})
                    },
                    complete: function () {
                        layer.close(loadstatus);
                    }
                }).done(function (response) {
                    if (response.code == 200) {
                        okLayer.greenTickMsg(response.msg, function () {
                            parent.location.reload();
                        });
                    } else if (response.code == 501) {
                        okLayer.yellowSighMsg(response.msg, function () {
                            location.reload();
                        });
                    } else if (response.code == 500) {
                        okLayer.redCrossMsg(response.msg, function () {
                            parent.location.reload();
                        });
                    }
                }).fail(function (error) {
                    okLayer.redCryMsg(error);
                })
                return false;//阻止表单跳转
            });

            //时间选择组件
            laydate.render({
                elem: '#LAY-component-form-group-date'
            });
        }
    )
</script>
</html>